<template>
	<view class="sigin-container">
		<view class="sigin-title">{{this.title}}</view>
		<view class="sigin-body">
			<view class="sigin-body-title">
				<view class="sigin-body-item">内容</view>
				<view class="sigin-body-item">发送人</view>
				<view class="sigin-body-item">创建时间</view>
				<view class="sigin-body-item">标志</view>
			</view>
			<view class="sigin-body-content" @click="onNoticeSender(instruction)"
				v-for="(instruction,i) in this.instructionsList">
				<view class="sigin-body-item">{{instruction.Content}}</view>
				<view class="sigin-body-item">{{instruction.Sname}}</view>
				<view class="sigin-body-item">{{instruction.CreateTime}}</view>
				<view class="sigin-body-item">{{instruction.Tag}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import service from '../../utils/http.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		name: "SignIn",
		data() {
			return {
				instructionsList: [],
				tag: 0,
				title: ''
			};
		},
		computed: {
			...mapState('m_user', ['userinfo'])
		},
		onLoad(option) {
			this.tag = parseInt(option.tag)
			if (this.tag == 1) {
				this.title = '预令指令'
			} else if (this.tag == 2) {
				this.title = '复诵指令'
			} else if (this.tag == 3) {
				this.title = '汇报指令'
			} else {
				this.title = ''
			}
			this.GetInstructionsList()
		},
		onShow() {
			this.GetInstructionsList()
		},
		methods: {
			...mapMutations('m_user', ['updateUserinfo']),
			GetInstructionsList(cb) {
				const id = this.userinfo.Sid
				service.get('/api/Instructions?sid=' + id + '&tag=' + this.tag)
					.then(response => {
						// console.log(response)
						const data = response.Data;
						this.instructionsList = JSON.parse(data)
						// console.log(this.instructionsList)
					})
					.catch(error => {
						console.error(error);
					});
			},
			onNoticeSender(instruction) {
				const msg = {
					Tag: this.tag + 1,
					SenderId: this.userinfo.Sid,
					ReceiverId: instruction.ReceiveId,
					Content: instruction.Content,
					Id: instruction.Id
				}
				const dataMsg = JSON.stringify(msg)
				// console.log('sigin', dataMsg)
				uni.sendSocketMessage({
					data: dataMsg,
					success(res) {
						// console.log('发送指令成功', res)
					}
				})
				uni.switchTab({
					url: '/pages/home/home'
				})
			}
		}
	}
</script>

<style lang="scss">
	.sigin-container {
		margin-left: 20px;
		margin-right: 20px;
		line-height: 30px;

		.sigin-title {
			text-align: center;
		}

		.sigin-body {

			.sigin-body-title,
			.sigin-body-content {
				display: flex;
				flex-direction: row;
				width: 100%;

				.sigin-body-item {
					width: 25%;
				}
			}
		}
	}
</style>